import { models } from '../db';

const { auth: AuthModel } = models;

export const validAuth = async (token: string): Promise<string> => {
  return new Promise(async (resolve, reject) => {
    if (!token) {
      return reject('请先登录');
    }
    const auth = await AuthModel.findOne({ where: { token } });
    if (!auth) {
      return reject('请先登录');
    }
    const authInfo = auth.dataValues;
    const { user_id } = authInfo;
    return resolve(user_id);
  });
};
